package com.demo.springboot.controller;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BookController {

    @ExceptionHandler // 只能处理局部异常
    public String error(Exception e){
        return "Exception: "+e.getMessage();
    }

    @GetMapping("/book/error1")
    public String error1(){
        throw new NullPointerException("Book.txt Not Found");
    }

    @GetMapping("/book/error2")
    public String error2(){
        throw new IllegalArgumentException("Argument Is Not Correct");
    }
}
